<?php
namespace Common\Models;

class UserAchievementModel extends \Phalcon\Mvc\Model {
  /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource() {
        return 'user_achievement';
    }

  // 加
  public function increment($type, $amount_left, $amount_right) {
    if(!is_numeric($amount_left)) {
      throw new \Exception('"c" is not a numeric');
    }
    if(!is_numeric($amount_right)) {
      throw new \Exception('"amount_right" is not a numeric');
    }

    switch($type) {
      case 'day':
        $this -> day_amount_left += $amount_left;
        $this -> day_amount_right += $amount_right;
        break;
      case 'month':
        $this -> month_amount_left += $amount_left;
        $this -> month_amount_right += $amount_right;
        break;
      default:
        throw new \Exception('"Type" is not a type of formulation');
        break;
    }
    return $this;
  }

  //减
  public function decrement() {
    return $this;
  }

  public function createLog($data = []) {
    $data = array_merge([
      'user_id' => $this -> user_id
    ], $data);
    $model = new UserAchievementLogModel($data);
    if(!$model -> create()) {
      throw new \Exception('"UserAchievementLogModel" Create failure');
    }
    return $this;
  }
}
?>